import React, { Component } from 'react'

export default class Page extends Component {

    state = {
        list: []
    }
    componentDidMount(){


        const list = []
        for (let i = 0; i < this.props.allNum / this.props.size; i++) {
            list.push(i + 1)
        }
        // console.log(list,this.props.allNum);
        this.setState({
            list: list
        })
    }


  render() {
    return (
      <div>
        {
            this.state.list.map(item => {
                return <span 
                onClick={()=>{
                    // 给父组件传递被点击的页码
                    this.props.getPage(item)
                }}
                className={ 
                    this.props.current === item 
                    ? 
                    'active pageNum' 
                    : 
                    'pageNum'
                } 
                key={item}
                >{item}</span>
            })
        }
      </div>
    )
  }
}
